from public.action import *
from public.tools import *
from public.testData import *
testCase = "DBshop0013_分类编辑"
firefox=getDriver()
openBrowser(firefox,urlAdmin)
logInAdmin(firefox)

adminMenu3(firefox,"商品管理","管理分类","商品分类")
# 1.点击添加分类按钮，分类名称“商品分类测试”,分类排序输入1。
firefox.find_element_by_partial_link_text("添加分类").click()
firefox.find_element_by_id("class_name").send_keys(goodsClassName)
firefox.find_element_by_id("class_sort").clear()
firefox.find_element_by_id("class_sort").send_keys("1")
# 2.点击“保存分类”按钮”。
firefox.find_element_by_xpath("//button").click()
time.sleep(5)
# 3.点击“商品分类测试”后方的分类编辑链接,进入商品分类编辑页面
firefox.find_element_by_xpath("//td[contains(.,'%s')]/following-sibling::td[4]/a[2]" % goodsClassName).click()
# 4.将"商品分类测试"的分类排序修改为4,点击保存分类按钮
firefox.find_element_by_id("class_sort").clear()
firefox.find_element_by_id("class_sort").send_keys("4")
firefox.find_element_by_xpath("(//button)[2]").click()
time.sleep(3)

#断言
shiji=firefox.find_element_by_xpath("//td[contains(.,'%s')]/following-sibling::td[2]/input" % goodsClassName).get_attribute("value")
try:
    if shiji == '4':
        writeLog("%s 测试通过" % testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()


